<?php

    // 连接数据库
    $conn = mysqli_connect('localhost:3306' , 'root' , 'root' , 'test2') ;

    if(!$conn) {
        die('数据库连接失败') ;
    }


    // 显示购物车  显示谁的购物车
    $uname = $_POST['username'] ;

    $res = [] ;
    if($uname) {
        // 联表查询
        //            
        $sql = "SELECT * FROM cart , goods_list WHERE cart.username = '$uname' AND cart.goods_id = goods_list.goods_id" ;
        $a = mysqli_query($conn , $sql) ;
        // 存入数组
        $list = [] ;
        while($data = mysqli_fetch_array($a)) {
            array_push($list , $data) ;
        }
        if($list) {
            $res['status'] = true ;
            $res['msg'] = '数据请求成功' ;
            $res['list'] = $list ;
        } else {
            $res['status'] = false ;
            $res['msg'] = '数据库错误' ;
        }
    } else {
        $res['status'] = false ;
        $res['msg'] = '前端数据错误' ;
    }


    echo(json_encode($res)) ;